function AddTextLine(data) {
  var tag = document.createElement("font");
  tag.setAttribute('size', '-1');
  tag.innerHTML = data;
  document.body.appendChild(tag);
  document.body.appendChild(document.createElement('br'));
}

function EvalJs(html) {
  var hd = document.getElementsByTagName("head")[0];
  var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
  var src_re = /\ssrc=([\'\"])(.*?)\1/i;
  var type_re = /\stype=([\'\"])(.*?)\1/i;
  var match;
  while (match = re.exec(html)) {
    try {
      var attrs = match[1];
      var src_match = attrs ? attrs.match(src_re) : false;
      if (src_match && src_match[2]) {
        // var s = document.createElement("script");
        // s.src = src_match[2];
        // var type_match = attrs.match(type_re);
        // if (type_match && type_match[2]) {
        //   s.type = type_match[2];
        // }
        // hd.appendChild(s);
      } else if (match[2] && match[2].length > 0) {
        if (match[2].indexOf('document.write') != -1) continue;
        if(window.execScript) {  
          window.execScript(match[2]);  
        } else {  
          window.eval(match[2]);  
        }  
      }
    } catch (exception) {
      AddTextLine(exception);
    } finally {
    }
  }
  // document.getElementById("div_response").innerHTML = r.responseText; 
}

function RequestProxies(url) {
  var r = new XMLHttpRequest();

  r.onreadystatechange = function() {
    if (r.readyState == 4) {
      var html = r.responseText;
      EvalJs(html);

      var pat = /<td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[^<]*<[sS][cC][rR][iI][pP][tT][^>]*>document.write\(([^<]+)\)<\/[sS][cC][rR][iI][pP][tT]>[^<]*<\/td>/ig;
      var match;
      while (match = pat.exec(html)) {
        var normal = true;
        var proxy = '';
        try {
          proxy = match[1] + eval(match[2]);
        } catch (exception) {
          normal = false;
        } finally {
        }
        if (normal) AddTextLine(proxy);
      }
    }
  }
  r.open("GET", url, true);
  r.send();
}

document.addEventListener('DOMContentLoaded', function () {
  pages = [
    'proxy1.html',
    'proxy2.html',
    'proxy3.html',
    'proxy4.html',
    'proxy5.html',
    'proxy6.html',
    'proxy7.html',
    'proxy8.html',
    'proxy9.html',
    'proxy10.html',
    'proxyedu1.html',
    'proxyedu2.html',
  ];
  for (i = 0; i < pages.length; ++i) {
    url = 'http://www.cnproxy.com/' + pages[i];
    RequestProxies(url);
  }
});
